from google.appengine.ext import db
import inspect
import utils
import types
class TaskInfo(db.Model):
    name = db.StringProperty()
    taskContent = db.TextProperty()
    planStartDate = db.DateProperty()
    planEndDate = db.DateProperty()
    planTime = db.FloatProperty()
    taskStartDate = db.DateProperty() 
    taskEndDate = db.DateProperty() 
    taskTime = db.FloatProperty()
    createDate = db.DateProperty(auto_now_add=True)
    state = db.StringProperty()
    level = db.FloatProperty()
    
    @classmethod
    def findTaskInfo(cls,state="0"):
        sql = "";
        if state=="0":
            return TaskInfo.gql("ORDER BY createDate")
        else:
            return TaskInfo.gql("where state=:1 order by createDate",state)
    
    def mergeBean(self,dic):
        #print("test Content:"+str(dir(dic).count("taskContent")))
        if(("name" in dic) and type(dic["name"]) is not types.NoneType):
            self.name=dic["name"]
        if(("taskContent" in dic) and type(dic["taskContent"]) is not types.NoneType):
            print("test Content:"+dic["taskContent"])
            self.taskContent=db.Text(dic["taskContent"])
        if(("planStartDate" in dic) and type(dic["planStartDate"]) is not types.NoneType):
            self.planStartDate=utils.stringToDate(dic["planStartDate"])
        if(("planEndDate" in dic) and type(dic["planEndDate"]) is not types.NoneType):
            self.planEndDate=utils.stringToDate(dic["planEndDate"])
        if(("taskStartDate" in dic) and type(dic["taskStartDate"]) is not types.NoneType):
            self.taskStartDate=utils.stringToDate(dic["taskStartDate"])
        if(("taskEndDate" in dic) and type(dic["taskEndDate"]) is not types.NoneType):
            self.taskEndDate=utils.stringToDate(dic["taskEndDate"])
        if(("planTime" in dic) and type(dic["planTime"]) is not types.NoneType):
            self.planTime=float(dic["planTime"])
        if(("taskTime" in dic) and type(dic["taskTime"]) is not types.NoneType):
            self.taskTime=float(dic["taskTime"])
        if(("state" in dic)  and type(dic["state"]) is not types.NoneType):
            self.state=dic["state"]
        if(("level" in dic) and type(dic["level"]) is not types.NoneType):
            self.level=float(dic["level"])
        

                